package com.googlecode.keepwalking;

public class Statistics {
	
	public static float average(float[] data) {
		float sum = 0;
		for(int i = 0; i < data.length; i++) {
			sum += data[i];
		}
		return sum / data.length;
	}
	
	public static float stdDev(float[] data, float mean) {
		float temp = 0;
		for(int i = 0; i < data.length; i++) {
			temp += (data[i] - mean) * (data[i] - mean);
		}
		return (float) Math.sqrt(temp / data.length);
	}
	
	public static float[] hpFilter(float[] data, float alpha) {
		float[] result = new float[data.length];
		float k = 0.0f;
		for(int i = 0; i < data.length; i++) {
			k = alpha * k + (1 - alpha) * data[i];
			result[i] = data[i] - k;
		}
		return result;
	}
	
}
